home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 007 / isrclck.aqm / isr-clck.asm
Assembly Source File  |  1985-04-29  |  16KB  |  253 lines

  1. ; |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
  2. ; ||                                                                         ||
  3. ; ||    SRC FILE :  ISR-CLCK.ASM      [ ver 1.01 @ 85/04/01 jmf ]            ||
  4. ; ||                                                                         ||
  5. ; ||    FUNCTION :  void set_clck() ; Load new interrupt vector              ||
  6. ; ||                void isr_clck() ; Generic clock interrupt 0x1c service   ||
  7. ; ||                void rst_clck() ; Restore original vector                ||
  8. ; ||                                                                         ||
  9. ; ||    COMMENTS :  This module includes the Lattice-C  DOS.MAC interface,   ||
  10. ; ||                which is created as follows ...                          ||
  11. ; ||                                                                         ||
  12. ; ||                  if 'd' model, then rename dm8086.mac dos.mac           ||
  13. ; ||                  if 'l' model, then rename lm8086.mac dos.mac           ||
  14. ; ||                  if 'p' model, then rename pm8086.mac dos.mac           ||
  15. ; ||                  if 's' model, then rename sm8086.mac dos.mac           ||
  16. ; ||                                                                         ||
  17. ; ||    CAUTIONS :  The original interrupt vector must be restored using     ||
  18. ; ||                the rst_clck() function prior to returning to dos.       ||
  19. ; ||                                                                         ||
  20. ; |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
  21.  
  22.   INCLUDE       DOS.MAC                         ;  lattice-c interface
  23.  
  24. ; =============================================================================
  25.  
  26.   INACTIVE      EQU     00000000B               ;  down-counter inactive
  27.   TIMEOUT0      EQU     00000001B               ;  timer_00 time out flag bit
  28.   TIMEOUT1      EQU     00000010B               ;  timer_01 time out flag bit
  29.   TIMEOUT2      EQU     00000100B               ;  timer_02 time out flag bit
  30.   TIMEOUT3      EQU     00001000B               ;  timer_03 time out flag bit
  31.   TIMEOUT4      EQU     00010000B               ;  timer_04 time out flag bit
  32.   TIMEOUT5      EQU     00100000B               ;  timer_05 time out flag bit
  33.   TIMEOUT6      EQU     01000000B               ;  timer_06 time out flag bit
  34.   TIMEOUT7      EQU     10000000B               ;  timer_07 time out flag bit
  35.  
  36. ; ( cont. ) ( cont. )
  37.  
  38. ; =============================================================================
  39.  
  40.                 DSEG                            ;  lattice-c segment macro
  41.  
  42. ; -----------------------------------------------------------------------------
  43. ; The clock interrupt service routine will support eight (8) timers, designated
  44. ; timer_00 thru timer_07.  Each is seperately declared as an unsigned, public
  45. ; variable.  A pointer to these eight variables, designated timer, is also de-
  46. ; fined.  This permits the user to view these variables as individual elements,
  47. ; as elements of the timer[] array, or as members of the timer structure.
  48. ; -----------------------------------------------------------------------------
  49.  
  50.   TIMER_00      DW      0                       ;  clock timer-counter # 0
  51.                 PUBLIC  TIMER_00                ;        declared public
  52.   TIMER_01      DW      0                       ;  clock timer-counter # 1
  53.                 PUBLIC  TIMER_01                ;        declared public
  54.   TIMER_02      DW      0                       ;  clock timer-counter # 2
  55.                 PUBLIC  TIMER_02                ;        declared public
  56.   TIMER_03      DW      0                       ;  clock timer-counter # 3
  57.                 PUBLIC  TIMER_03                ;        declared public
  58.   TIMER_04      DW      0                       ;  clock timer-counter # 4
  59.                 PUBLIC  TIMER_04                ;        declared public
  60.   TIMER_05      DW      0                       ;  clock timer-counter # 5
  61.                 PUBLIC  TIMER_05                ;        declared public
  62.   TIMER_06      DW      0                       ;  clock timer-counter # 6
  63.                 PUBLIC  TIMER_06                ;        declared public
  64.   TIMER_07      DW      0                       ;  clock timer-counter # 7
  65.                 PUBLIC  TIMER_07                ;        declared public
  66. ; ----------------------------------------------
  67.                 IF      LDATA                   ;  if large data model
  68.   TIMER         DD      TIMER_00                ;     then 32-bit pointer
  69.                 ELSE                            ;  if small data model
  70.   TIMER         DW      TIMER_00                ;     then 16-bit pointer
  71.                 ENDIF                           ;  end conditional
  72. ;               --------------------------------
  73.                 PUBLIC  TIMER                   ;  pointer declared public
  74.  
  75. ; -----------------------------------------------------------------------------
  76. ; In the event that one of the timer / down-counters decrements to zero, the
  77. ; appropriate bit will be set in the public variable clck_flg.
  78. ; -----------------------------------------------------------------------------
  79.  
  80.   CLCK_FLG      DW      0                       ;  bit-mapped time-out flag
  81.                 PUBLIC  CLCK_FLG                ;        declared public
  82.  
  83. ; -----------------------------------------------------------------------------
  84. ; Before loading the clock interrupt service routine, we must get and save the
  85. ; original vector so it can be restored prior to exiting to dos.  Therefore ...
  86. ; -----------------------------------------------------------------------------
  87.  
  88.   OLD1C_IV      LABEL   DWORD                   ;  32-bit interrupt vector
  89.   OLD1C_IP      DW      ?                       ;     instruction pointer
  90.   OLD1C_CS      DW      ?                       ;     code segment
  91.  
  92. ; =============================================================================
  93.  
  94.                 ENDDS                           ;  end segment macro
  95.  
  96. ; ( cont. ) ( cont. )
  97.  
  98.                 PSEG                            ;  lattice-c segment macro
  99.  
  100. ; |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
  101. ; ||                                                                         ||
  102. ; ||    FUNCTION :  void set_clck() ; Load new interrupt vector              ||
  103. ; ||                                                                         ||
  104. ; |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
  105.  
  106.                 IF      LPROG                   ;  if large program model
  107.   SET_CLCK      PROC    FAR                     ;     define as far procedure
  108.                 ELSE                            ;  otherwise
  109.   SET_CLCK      PROC    NEAR                    ;     define as near procedure
  110.                 ENDIF                           ;  end conditional
  111.                 PUBLIC  SET_CLCK                ;  declare public
  112. ; ----------------------------------------------
  113.                 PUSH    ES                      ;  protect context
  114.                 PUSH    DS                      ;     ...
  115.                 MOV     AX, DATA                ;  ensure proper segment
  116.                 MOV     DS, AX                  ;     ...
  117. ; ----------------------------------------------
  118.                 MOV     AX, 351CH               ;  get original vector
  119.                 INT     021H                    ;      via dos service
  120.                 MOV     OLD1C_IP, BX            ;  save offset
  121.                 MOV     OLD1C_CS, ES            ;  and code segment
  122.                 MOV     DX, OFFSET ISR_CLCK     ;  get new vector offset
  123.                 PUSH    CS                      ;  and code segment
  124.                 POP     DS                      ;     ...
  125.                 MOV     AX, 251CH               ;  set new clock vector
  126.                 INT     021H                    ;      via dos service
  127.                 POP     DS                      ;  restore context
  128.                 POP     ES                      ;     ...
  129.                 RET                             ;  return to caller
  130. ; ----------------------------------------------
  131.   SET_CLCK      ENDP                            ;  end procedure
  132.  
  133. ; ( cont. ) ( cont. )
  134.  
  135. ; |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
  136. ; ||                                                                         ||
  137. ; ||    FUNCTION :  void isr_clck() ; Generic clock interrupt 0x1c service   ||
  138. ; ||                                                                         ||
  139. ; ||    COMMENTS :  Interrupt 0x1c is invoked by the IBM-BIOS approximately  ||
  140. ; ||                18.2 times per second.  The following service monitors   ||
  141. ; ||                8 unsigned timer / down-counters and communicates to     ||
  142. ; ||                the user via the bit-mapped clck_flg as follows ...      ||
  143. ; ||                                                                         ||
  144. ; ||                         for each timer-n, 0 <= n <= 7                   ||
  145. ; ||                           if timer-n is inactive ( i.e., 0 )            ||
  146. ; ||                              continue                                   ||
  147. ; ||                           otherwise                                     ||
  148. ; ||                              decrement timer-n                          ||
  149. ; ||                              if timer-n has timed-out                   ||
  150. ; ||                                 set bit-n of clck_flg                   ||
  151. ; ||                                                                         ||
  152. ; |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
  153.  
  154.   ISR_CLCK      PROC    FAR                     ;  clock interrupt service
  155.                 PUBLIC  ISR_CLCK                ;  declared public
  156. ; ----------------------------------------------
  157.                 STI                             ;  enable interrupts
  158.                 PUSH    AX                      ;  protect context
  159.                 PUSH    DS                      ;     ...
  160.                 MOV     AX, DATA                ;  ensure proper segment
  161.                 MOV     DS, AX                  ;     ...
  162. ; ----------------------------------------------
  163.   CHECK_00:     CMP     TIMER_00, INACTIVE      ;  is timer inactive?
  164.                 JE      CHECK_01                ;  y: test next timer
  165.                 DEC     TIMER_00                ;  n: decrement timer
  166.                 JNZ     CHECK_01                ;     if not timeout, cont.
  167.                 OR      CLCK_FLG, TIMEOUT0      ;        else flag timeout
  168. ; ----------------------------------------------
  169.   CHECK_01:     CMP     TIMER_01, INACTIVE      ;  is timer inactive?
  170.                 JE      CHECK_02                ;  y: test next timer
  171.                 DEC     TIMER_01                ;  n: decrement timer
  172.                 JNZ     CHECK_02                ;     if not timeout, cont.
  173.                 OR      CLCK_FLG, TIMEOUT1      ;        else flag timeout
  174. ; ----------------------------------------------
  175.   CHECK_02:     CMP     TIMER_02, INACTIVE      ;  is timer inactive?
  176.                 JE      CHECK_03                ;  y: test next timer
  177.                 DEC     TIMER_02                ;  n: decrement timer
  178.                 JNZ     CHECK_03                ;     if not timeout, cont.
  179.                 OR      CLCK_FLG, TIMEOUT2      ;        else flag timeout
  180. ; ----------------------------------------------
  181.   CHECK_03:     CMP     TIMER_03, INACTIVE      ;  is timer inactive?
  182.                 JE      CHECK_04                ;  y: test next timer
  183.                 DEC     TIMER_03                ;  n: decrement timer
  184.                 JNZ     CHECK_04                ;     if not timeout, cont.
  185.                 OR      CLCK_FLG, TIMEOUT3      ;        else flag timeout
  186.  
  187. ; ( cont. ) ( cont. )
  188.  
  189. ; ----------------------------------------------
  190.   CHECK_04:     CMP     TIMER_04, INACTIVE      ;  is timer inactive?
  191.                 JE      CHECK_05                ;  y: test next timer
  192.                 DEC     TIMER_04                ;  n: decrement timer
  193.                 JNZ     CHECK_05                ;     if not timeout, cont.
  194.                 OR      CLCK_FLG, TIMEOUT4      ;        else flag timeout
  195. ; ----------------------------------------------
  196.   CHECK_05:     CMP     TIMER_05, INACTIVE      ;  is timer inactive?
  197.                 JE      CHECK_06                ;  y: test next timer
  198.                 DEC     TIMER_05                ;  n: decrement timer
  199.                 JNZ     CHECK_06                ;     if not timeout, cont.
  200.                 OR      CLCK_FLG, TIMEOUT5      ;        else flag timeout
  201. ; ----------------------------------------------
  202.   CHECK_06:     CMP     TIMER_06, INACTIVE      ;  is timer inactive?
  203.                 JE      CHECK_07                ;  y: test next timer
  204.                 DEC     TIMER_06                ;  n: decrement timer
  205.                 JNZ     CHECK_07                ;     if not timeout, cont.
  206.                 OR      CLCK_FLG, TIMEOUT6      ;        else flag timeout
  207. ; ----------------------------------------------
  208.   CHECK_07:     CMP     TIMER_07, INACTIVE      ;  is timer inactive?
  209.                 JE      END_CLCK                ;  y: done
  210.                 DEC     TIMER_07                ;  n: decrement timer
  211.                 JNZ     END_CLCK                ;     if not timeout, done
  212.                 OR      CLCK_FLG, TIMEOUT7      ;        else flag timeout
  213. ; ----------------------------------------------
  214.   END_CLCK:     POP     DS                      ;  restore context
  215.                 POP     AX                      ;     ...
  216.                 IRET                            ;  return from interrupt
  217. ; ----------------------------------------------
  218.   ISR_CLCK      ENDP                            ;  end procedure
  219.  
  220. ; ( cont. ) ( cont. )
  221.  
  222. ; |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
  223. ; ||                                                                         ||
  224. ; ||    FUNCTION :  void rst_clck() ; Restore original vector                ||
  225. ; ||                                                                         ||
  226. ; |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
  227.  
  228.                 IF      LPROG                   ;  if large program model
  229.   RST_CLCK      PROC    FAR                     ;     define as far procedure
  230.                 ELSE                            ;  otherwise
  231.   RST_CLCK      PROC    NEAR                    ;     define as near procedure
  232.                 ENDIF                           ;  end conditional
  233.                 PUBLIC  RST_CLCK                ;  declare public
  234. ; ----------------------------------------------
  235.                 PUSH    DS                      ;  protect context
  236.                 MOV     AX, DATA                ;  ensure proper segment
  237.                 MOV     DS, AX                  ;     ...
  238. ; ----------------------------------------------
  239.                 LDS     DX, OLD1C_IV            ;  load original vector
  240.                 MOV     AX, 251CH               ;  set the clock vector
  241.                 INT     021H                    ;      via dos service
  242. ; ----------------------------------------------
  243.                 POP     DS                      ;  restore context
  244.                 RET                             ;  return to caller
  245. ; ----------------------------------------------
  246.   RST_CLCK      ENDP                            ;  end procedure
  247.  
  248. ; =============================================================================
  249.  
  250.                 ENDPS                           ;  end segment macro
  251.                 END                             ;  end of file
  252.  
  253.